<?php

namespace App\Repositories\User;

use App\Models\User\UsersBindInfoModel;


class BindInfoRepository
{

    private $model;


    public function __construct(
        UsersBindInfoModel $model
    )
    {
        $this->model = $model;
    }


    /**
     * @param $openID
     * @param $bindRef
     *
     * @return array
     */
    public function getUserBindInfoByOpenID($openID, $bindRef)
    {
        $model = $this->model;
        try{
            $data = $model
                ->where('openID', '=', $openID)
                ->where('openIDCRC32', '=', createCRC32($openID))
                ->where('bindStatus', '=', 1)
                ->where('bindRef', '=', $bindRef)
                ->first();

            return $data;
        }catch (\Exception $exception){
            return [];
        }
    }

    /**
     * demo
     * @param $openID
     *
     * @return bool
     */
    public function bindInfo(
        $openID
    )
    {
        try {
            $add['openID'] = $openID;
            $add['openIDCRC32'] = createCRC32($openID);

            $model = $this->model;

            return $model->insert($add);

        } catch (\Exception $exception) {

            return false;
        }


    }


}